package  nid.display
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.media.Camera;
	import flash.media.Video;
	
	/**
	 * ...
	 * @author Nidin.P.Vinayak
	 */
	public class VideoDisplay extends Sprite
	{
		private var _video:Video;
		private var _container:Sprite;
		
		public function VideoDisplay() 
		{
			_video = new Video();
			_container = new Sprite();
			_video.name = 'video';
			
			addChild(_container);
		}
		public function addVideo(obj:DisplayObject):DisplayObject {
			if (_container.getChildByName('video') != null) {
				_container.removeChild(_container.getChildByName('video'));
			}
			obj.name = 'video';
			_container.addChild(resize(obj));
			return DisplayObject(obj);
		}
		public function attachCamera(cam:Camera):void {
			if (_container.getChildByName('video') != null) {
				_container.removeChild(_container.getChildByName('video'));
			}
			_video.attachCamera(cam);
			_container.addChild(resize(_video));
		}
		private function resize(obj:DisplayObject):DisplayObject{
			var VideoW:Number = 210;
			var VideoH:Number = 152;
			
			VideoH 			= 	VideoH == 0 ? VideoW : VideoH;			
			obj.width 		= 	VideoW;
			obj.height 		= 	VideoH;
			obj.scaleX < obj.scaleY ? obj.scaleY = obj.scaleX : obj.scaleX = obj.scaleY;
			obj.x			=	(VideoW / 2) - (obj.width / 2);
			obj.y			=   (VideoH / 2) - (obj.height / 2);
			
			return obj;
		}
	}

}